package ballParadigm;

import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.border.BevelBorder;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JTextField;

public class normalGameFrame extends JFrame {
	
	//Game Objects Start
	ArrayList<GameObjects> gameObjects = new ArrayList<GameObjects>();
	ArrayList<JLabel> objectLabels = new ArrayList<JLabel>();
	ArrayList<Ball> myBall = new ArrayList<Ball>();
	ArrayList<JLabel> panelLabels = new ArrayList<JLabel>();
	ArrayList<GameObjects> panelObjects = new ArrayList<GameObjects>();
	//Game Objects End
	String backgroundimage;
	JLabel scoreLabel;
	boolean newObjectActivated=false;
	GameObjects newGameObject;
	final Point hotspot = new Point(0, 0);
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	boolean simulationOn=false;
	Timer timer;
	JPanel palette;
	JLayeredPane simulationPanel;
	JPanel panel;
	double gravity=0;
	collusion col = new collusion();
	int timertime = 50;
	int currentlevel = 0;
	boolean gameWon = false;
	
	ArrayList<String> codes = new ArrayList<String>();
	
	private JPanel contentPane;
	private JTextField levelCodeText;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					normalGameFrame frame = new normalGameFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public normalGameFrame() {
		
		codes.add("1");
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 583);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		panel = new JPanel();
		panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null,
				null));
		panel.setBounds(717, 50, 177, 500);
		contentPane.add(panel);
		panel.setLayout(null);

		JLabel lblNewLabel_1 = new JLabel("Platte");
		lblNewLabel_1.setBounds(61, 24, 61, 16);
		panel.add(lblNewLabel_1);

		JButton btnStartSimulation = new JButton("Simulation Start/Pause");
		btnStartSimulation.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(simulationOn==false){
					timer = new Timer();
					timer.scheduleAtFixedRate(new TimerTask() {

						@Override
						public void run() {


							for(int i=0; i<gameObjects.size();i++){
								if(col.collide(gameObjects.get(i), myBall.get(0))){
									gameObjects.get(i).ballTouched(col.collusionSide(gameObjects.get(i), myBall.get(0)), myBall, objectLabels, i);
								}
							}
							myBall.get(0).moveForward(gravity);
							objectLabels.get(0).setLocation((int)Math.round(myBall.get(0).x), (int)Math.round(myBall.get(0).y));
							scoreLabel.setText(Integer.toString(myBall.get(0).score));
							if(myBall.get(0).y>500)
								myBall.get(0).dead=true;
							
							if(myBall.get(0).dead==true){
								timer.cancel();
								btnStartSimulation.disable();
								scoreLabel.setText("GAME OVER!");
							}else if(myBall.get(0).won==true){
								timer.cancel();
								btnStartSimulation.disable();
								scoreLabel.setText("You Won!");
								saveGame.highScores.add("Name: "+JOptionPane.showInputDialog("Level Code is: "+codes.get(currentlevel-1) +"\nPlease enter your name:")+" Score: "+myBall.get(0).score+" Level: "+currentlevel);
								if(currentlevel==1){
									setLevel2();
								}
							}
						}
					}, 100, 25);//First time elapse, second time interval
					simulationOn=true;
				}else{
					simulationOn=false;
					timer.cancel();
					simulationPanel.repaint();
					palette.repaint();
				}
			}
		});
		btnStartSimulation.setBounds(6, 434, 165, 50);
		panel.add(btnStartSimulation);
		
		palette = new JPanel();
		palette.setAutoscrolls(true);
		palette.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		palette.setBounds(6, 52, 165, 370);
		panel.add(palette);
		palette.setLayout(null);

		JButton btnRestartGame = new JButton("Restart Game");
		btnRestartGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(currentlevel==1)
				setLevel1();
				else if(currentlevel==2)
					setLevel2();
				btnStartSimulation.enable();
			}
		});
		btnRestartGame.setBounds(6, 16, 113, 22);
		contentPane.add(btnRestartGame);

		JButton btnSaveGame = new JButton("Save Game");
		btnSaveGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				saveGame.normalmyBall.clear();
				saveGame.normalgameObjects.clear();
				saveGame.normalpanelObjects.clear();
				
				for(GameObjects o: gameObjects){
					GameObjects newObject = o;
					saveGame.normalgameObjects.add(newObject);
				}
				for(Ball o: myBall){
					Ball newObject = o;
					saveGame.normalmyBall.add(newObject);
				}
				for(GameObjects o: panelObjects){
					GameObjects newObject = o;
					saveGame.normalpanelObjects.add(newObject);
				}
				saveGame.normalbackgroundimage=backgroundimage;
			}
		});
		btnSaveGame.setBounds(131, 16, 113, 22);
		contentPane.add(btnSaveGame);

		JButton btnLoadGame = new JButton("Load Game");
		btnLoadGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				loadGame();

			}
		});
		btnLoadGame.setBounds(256, 16, 113, 22);
		contentPane.add(btnLoadGame);

		JButton btnQuickLevel = new JButton("Quit Level");
		btnQuickLevel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnQuickLevel.setBounds(381, 16, 113, 22);
		contentPane.add(btnQuickLevel);
		
		simulationPanel = new JLayeredPane();
		simulationPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		simulationPanel.setBounds(6, 50, 699, 500);
		contentPane.add(simulationPanel);
		
		JLabel lblScore = new JLabel("Score: ");
		lblScore.setBounds(752, 16, 50, 16);
		contentPane.add(lblScore);
		
		scoreLabel = new JLabel("");
		scoreLabel.setBounds(794, 6, 100, 32);
		contentPane.add(scoreLabel);
		
		levelCodeText = new JTextField();
		levelCodeText.setBounds(580, 12, 72, 28);
		contentPane.add(levelCodeText);
		levelCodeText.setColumns(10);
		
		JLabel lblLevelCode = new JLabel("Level Code:");
		lblLevelCode.setBounds(506, 18, 84, 16);
		contentPane.add(lblLevelCode);
		
		JButton btnNewButton = new JButton("Enter");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(levelCodeText.getText().equals("1")){
					setLevel1();
					levelCodeText.setText("**");
				}
				else if(levelCodeText.getText().equals("2")){
					setLevel2();
					levelCodeText.setText("**");
				}
			}
		});
		btnNewButton.setBounds(661, 9, 79, 29);
		contentPane.add(btnNewButton);
		
		simulationPanel.addMouseListener(new MouseAdapter() {
		    @Override
		    public void mouseClicked(MouseEvent e) {

		        if(newObjectActivated==true){

		        	newGameObject.x=e.getX();
		        	newGameObject.y=e.getY();
		        	gameObjects.add(newGameObject);
		        	objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
		    		//objectLabels.get(objectLabels.size()-1).setIcon(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image)));
		    		objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
		    		simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
		    		simulationPanel.repaint();
		    		newObjectActivated=false;
			    	simulationPanel.setCursor (Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
		        }
		    }
		});
		setLevel1();
	}
	public void setLevel1(){

		simulationPanel.removeAll();
		palette.removeAll();
		
		myBall.clear();
		objectLabels.clear();
		gameObjects.clear();
		panelObjects.clear();
		panelLabels.clear();
		
	gravity=0.1;
	//Inside the simulationPanel
	myBall.add(new Basketball(5, 25, 1,0));//Creates the ball and places it
	objectLabels.add(new JLabel(""));
	objectLabels.get(objectLabels.size()-1).setIcon(new ImageIcon(freelanceGameFrame.class.getResource(myBall.get(0).image)));
	objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(myBall.get(0).x), (int)Math.round(myBall.get(0).y), myBall.get(0).WIDTH, myBall.get(0).HEIGHT);
	simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
	simulationPanel.repaint();
	
	
	gameObjects.add(new PlatformHorizontal(75, 250));//Creates the ball and places it
	objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
	objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
	simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
	simulationPanel.repaint();
	
	gameObjects.add(new Esnaf(70, 180));//Creates the ball and places it
	objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
	objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
	simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
	simulationPanel.repaint();
	
	gameObjects.add(new Door(650, 425));//Creates the ball and places it
	objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
	objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
	simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
	simulationPanel.repaint();
	//Inside simulationPanel end
	
	//Inside panel
	
	panelObjects.add(new PlatformHorizontal(5, 20));//A panel and its action listener **change this**
	panelLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(panelObjects.get(panelObjects.size()-1).image))));
	panelLabels.get(panelLabels.size()-1).setBounds((int)Math.round(panelObjects.get(panelObjects.size()-1).x), (int)Math.round(panelObjects.get(panelObjects.size()-1).y), panelObjects.get(panelObjects.size()-1).WIDTH, panelObjects.get(panelObjects.size()-1).HEIGHT);
	palette.add(panelLabels.get(panelLabels.size()-1));
	palette.repaint();

	panelLabels.get(panelLabels.size()-1).addMouseListener(new MouseAdapter()  
	{  
	    public void mouseClicked(MouseEvent e)
	    {  
	    	simulationPanel.setCursor(getToolkit().createCustomCursor(toolkit.getImage(freelanceGameFrame.class.getResource("/ballParadigm/platformhorizontal.png")) , hotspot, "Mouseumla"));//**change image in this**
	    	newGameObject = new PlatformHorizontal(0,0);//**changethis**
	    	newObjectActivated = true;
	    }  
	}); 
	
	//Inside panel end
	backgroundimage="background1.gif";
	setBackground(backgroundimage);
	
	currentlevel=1;
	
}
	public void setLevel2(){

        simulationPanel.removeAll();
        palette.removeAll();
        
        myBall.clear();
        objectLabels.clear();
        gameObjects.clear();
        panelObjects.clear();
        panelLabels.clear();
        
    gravity=0.1;
    
  //Inside the simulationPanel
    myBall.add(new Bowlingball(5, 25, 1,0));//Creates the ball and places it
    objectLabels.add(new JLabel(""));
    objectLabels.get(objectLabels.size()-1).setIcon(new ImageIcon(freelanceGameFrame.class.getResource(myBall.get(0).image)));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(myBall.get(0).x), (int)Math.round(myBall.get(0).y), myBall.get(0).WIDTH, myBall.get(0).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new Door(650, 425));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new PlatformHorizontal(150, 250));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new PlatformHorizontal(246, 250));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new PlatformHorizontal(320, 250));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new PlatformHorizontal(250, 150));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new PlatformVertical(670, 150));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new Trampoline(50, 425));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new Esnaf(200, 180));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    
    gameObjects.add(new Teyze(270, 80));//Creates the ball and places it
    objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
    objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
    simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
    simulationPanel.repaint();
    //Inside simulationPanel end
    
    //Inside items palette 
    panelObjects.add(new PlatformHorizontal(5, 20));//A panel and its action listener **change this**
    panelLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(panelObjects.get(panelObjects.size()-1).image))));
    panelLabels.get(panelLabels.size()-1).setBounds((int)Math.round(panelObjects.get(panelObjects.size()-1).x), (int)Math.round(panelObjects.get(panelObjects.size()-1).y), panelObjects.get(panelObjects.size()-1).WIDTH, panelObjects.get(panelObjects.size()-1).HEIGHT);
    palette.add(panelLabels.get(panelLabels.size()-1));
    palette.repaint();

    panelLabels.get(panelLabels.size()-1).addMouseListener(new MouseAdapter()  
    {  
        public void mouseClicked(MouseEvent e)
        {  
            simulationPanel.setCursor(getToolkit().createCustomCursor(toolkit.getImage(freelanceGameFrame.class.getResource("/ballParadigm/platformhorizontal.png")) , hotspot, "Mouseumla"));//**change image in this**
            newGameObject = new PlatformHorizontal(0,0);//**changethis**
            newObjectActivated = true;
        }  
    }); 
    
    panelObjects.add(new PlatformVertical(50, 150));//A panel and its action listener **change this**
    panelLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(panelObjects.get(panelObjects.size()-1).image))));
    panelLabels.get(panelLabels.size()-1).setBounds((int)Math.round(panelObjects.get(panelObjects.size()-1).x), (int)Math.round(panelObjects.get(panelObjects.size()-1).y), panelObjects.get(panelObjects.size()-1).WIDTH, panelObjects.get(panelObjects.size()-1).HEIGHT);
    palette.add(panelLabels.get(panelLabels.size()-1));
    palette.repaint();

    panelLabels.get(panelLabels.size()-1).addMouseListener(new MouseAdapter()  
    {  
        public void mouseClicked(MouseEvent e)  
        {  
            simulationPanel.setCursor(getToolkit().createCustomCursor(toolkit.getImage(freelanceGameFrame.class.getResource("/ballParadigm/platformvertical.png")) , hotspot, "Mouseumla"));//**change image in this**
            newGameObject = new PlatformVertical(0,0);//**change this**
            newObjectActivated = true;
        }  
    });
    
    panelObjects.add(new SpringHorizontal(25, 300));//A panel and its action listener **change this**
    panelLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(panelObjects.get(panelObjects.size()-1).image))));
    panelLabels.get(panelLabels.size()-1).setBounds((int)Math.round(panelObjects.get(panelObjects.size()-1).x), (int)Math.round(panelObjects.get(panelObjects.size()-1).y), panelObjects.get(panelObjects.size()-1).WIDTH, panelObjects.get(panelObjects.size()-1).HEIGHT);
    palette.add(panelLabels.get(panelLabels.size()-1));
    palette.repaint();

    panelLabels.get(panelLabels.size()-1).addMouseListener(new MouseAdapter()  
    {  
        public void mouseClicked(MouseEvent e)
        {  
            simulationPanel.setCursor(getToolkit().createCustomCursor(toolkit.getImage(freelanceGameFrame.class.getResource("/ballParadigm/springhorizontal.png")) , hotspot, "Mouseumla"));//**change image in this**
            newGameObject = new SpringHorizontal(0,0);//**changethis**
            newObjectActivated = true;
        }  
    }); 
    
    backgroundimage="background2.gif";
    setBackground(backgroundimage);
    
    currentlevel=2;
	}
	public void setBackground(String backgroundName){
		JLabel gameBackground = new JLabel("");
		gameBackground.setIcon(new ImageIcon(freelanceGameFrame.class.getResource(backgroundName)));
		gameBackground.setBounds(0, 0, 699, 500);
		simulationPanel.add(gameBackground,-5);
		simulationPanel.repaint();
	}
	public void loadGame(){
		simulationPanel.removeAll();
		palette.removeAll();
		simulationPanel.repaint();
		palette.repaint();
		myBall.clear();
		objectLabels.clear();
		gameObjects.clear();
		panelObjects.clear();
		panelLabels.clear();
		
		for(Ball o: saveGame.normalmyBall){
			Ball newBall = o;
			myBall.add(newBall);//Creates the ball and places it
			objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(myBall.get(0).image))));
			objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(myBall.get(0).x), (int)Math.round(myBall.get(0).y), myBall.get(0).WIDTH, myBall.get(0).HEIGHT);
			simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
			simulationPanel.repaint();
		}
		for(GameObjects o: saveGame.normalgameObjects){
			GameObjects newObject = o;
			gameObjects.add(newObject);//Creates the ball and places it
			objectLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(gameObjects.get(gameObjects.size()-1).image))));
			objectLabels.get(objectLabels.size()-1).setBounds((int)Math.round(gameObjects.get(gameObjects.size()-1).x), (int)Math.round(gameObjects.get(gameObjects.size()-1).y), gameObjects.get(gameObjects.size()-1).WIDTH, gameObjects.get(gameObjects.size()-1).HEIGHT);
			simulationPanel.add(objectLabels.get(objectLabels.size()-1),1);
			simulationPanel.repaint();
		}
		for(GameObjects o: saveGame.normalpanelObjects){
			GameObjects newObject = o;
			panelObjects.add(newObject);//A panel and its action listener **change this**
			panelLabels.add(new JLabel(new ImageIcon(freelanceGameFrame.class.getResource(panelObjects.get(panelObjects.size()-1).image))));
			panelLabels.get(panelLabels.size()-1).setBounds((int)Math.round(panelObjects.get(panelObjects.size()-1).x), (int)Math.round(panelObjects.get(panelObjects.size()-1).y), panelObjects.get(panelObjects.size()-1).WIDTH, panelObjects.get(panelObjects.size()-1).HEIGHT);
			palette.add(panelLabels.get(panelLabels.size()-1));
			palette.repaint();

			panelLabels.get(panelLabels.size()-1).addMouseListener(new MouseAdapter()  
			{  
			    public void mouseClicked(MouseEvent e)  
			    {  
			    	simulationPanel.setCursor(getToolkit().createCustomCursor(toolkit.getImage(freelanceGameFrame.class.getResource(newObject.image)) , hotspot, "Mouseumla"));//**change image in this**
			    	newGameObject = new Teyze(0,0);//**change this**
			    	newObjectActivated = true;
			    }  
			}); 
		}
		backgroundimage=saveGame.normalbackgroundimage;
		setBackground(backgroundimage);

	}
}
